package utilities;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailUtilities {

	public static boolean sendMail(String fromName, String fromAddress,
								   String toName, String toAddress,
						           String subject,
						           String messageBody) {
		boolean returnStatus = true;
		
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		

		try {
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress(fromAddress, fromName));
			msg.addRecipient(Message.RecipientType.TO,
			            new InternetAddress(toAddress, toName));
			msg.setSubject(subject);
			msg.setText(messageBody);
			Transport.send(msg);
		} catch (Exception e) {
			e.printStackTrace();
			returnStatus = false;
		}
		
		return returnStatus;
	}

}
